﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Checkers.Common
{
    /// <summary>
    /// This class represents all the data of a single game
    /// </summary>
    public class GameData
    {
        // Data members
        private int m_GameBoardSize;
        private GameBoard m_GameBoard;
        private GamePlayer m_Player1;
        private GamePlayer m_Player2;
        private GamePlayer m_CurrPlayer;
        private eGameType m_GameType;
        private eGameStatus m_GameStatus;

        /// <summary>
        /// Return the Board of the game
        /// </summary>
        public GameBoard GameBoard
        {
            get
            {
                return m_GameBoard;
            }

            set
            {
                m_GameBoard = value;
            }
        }

        /// <summary>
        /// Return Player 1 
        /// </summary>
        public GamePlayer Player1
        {
            get
            {
                return m_Player1;
            }

            set
            {
                m_Player1 = value;
            }
        }

        /// <summary>
        /// Return Player 2
        /// </summary>
        public GamePlayer Player2
        {
            get
            {
                return m_Player2;
            }

            set
            {
                m_Player2 = value;
            }
        }

        /// <summary>
        /// Gets the winning player of the game. If theres no winning situation null is returned.
        /// </summary>
        public GamePlayer WinnerPlayer
        {
            get
            {
                GamePlayer winnerPlayer = null;

                // If theres a winning situation
                if (this.GameStatus == eGameStatus.Win || this.GameStatus == eGameStatus.Forfeit)
                {
                    eGamePawnType victoryPawnType =
                        this.GameBoard.WhitePawns == 0 ? eGamePawnType.Black : eGamePawnType.White;
                    winnerPlayer =
                        this.Player1.PlayerPawnType == victoryPawnType ? this.Player1 : this.Player2;
                }

                return winnerPlayer;
            }
        }
        
        /// <summary>
        /// Return the current player of the game
        /// </summary>
        public GamePlayer CurrentPlayer
        {
            get
            {
                return m_CurrPlayer;
            }

            set
            {
                m_CurrPlayer = value;
            }
        }

        /// <summary>
        /// Return the game type
        /// </summary>
        public eGameType GameType
        {
            get
            {
                return m_GameType;
            }

            set
            {
                m_GameType = value;
            }
        }

        /// <summary>
        /// Gets and sets the game's board size
        /// </summary>
        public int GameBoardSize
        {
            get
            {
                return m_GameBoardSize;
            }

            set
            {
                m_GameBoardSize = value;
            }
        }

        /// <summary>
        /// Return the status of the game
        /// </summary>
        public eGameStatus GameStatus
        {
            get
            {
                return m_GameStatus;
            }

            set
            {
                m_GameStatus = value;
            }
        }
    }
}
